﻿#include "widget.h"
#include "ui_widget.h"
#include <QDebug>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    /* 开启定时器 */
    timerID1 = this->startTimer(3000); //1000ms
    timerID2 = this->startTimer(2000);
    timerID3 = this->startTimer(1000);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::mousePressEvent(QMouseEvent *event)
{
    qDebug() << "鼠标按键按下";
}

void Widget::mouseReleaseEvent(QMouseEvent *event)
{
    qDebug() << "鼠标按键释放";
}

void Widget::mouseMoveEvent(QMouseEvent *event)
{
    //globalPos：获取整个屏幕的坐标；pos：获取窗口的坐标
    qDebug() << "鼠标移动" << event->globalPos() << "(" << event->pos() << ")";
}

void Widget::mouseDoubleClickEvent(QMouseEvent *event)
{
    qDebug() << "鼠标按键双击";
}

void Widget::leaveEvent(QEvent *event)
{
    qDebug() << "鼠标离开控件";
}

void Widget::enterEvent(QEvent *event)
{
    qDebug() << "鼠标在控件上";
}

void Widget::keyPressEvent(QKeyEvent *event)
{
    qDebug() << QString(event->key()) << "键按下";
}

void Widget::keyReleaseEvent(QKeyEvent *event)
{
    qDebug() << QString(event->key()) << "键释放";
}

void Widget::paintEvent(QPaintEvent *event)
{
    qDebug() << "绘图事件触发";
}

void Widget::timerEvent(QTimerEvent *event)
{
    if(event->timerId() == timerID1)
    {
        qDebug() << "定时器ID1触发" << timerID1;
    }
    if(event->timerId() == timerID2)
    {
        qDebug() << "定时器ID2触发" << timerID2;
    }
    if(event->timerId() == timerID3)
    {
        qDebug() << "定时器ID3触发" << timerID3;
    }
}

bool Widget::event(QEvent *event)
{
    if(event->type() == QEvent::MouseButtonPress)
    {
        qDebug() << "QEvent::MouseButtonPress";
        return false;
    }

    /* 对于当前不需要处理的其他事件，交给基类来处理 */
    return QWidget::event(event);
}

